package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsUser;
import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 千峰教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@CrossOrigin("*")
@RestController
@RequestMapping("/admin/user")
public class AdminUserController {

    @Autowired
    DtsUserService userService;

    @GetMapping("/list")
    public Object list(
            @RequestParam(name = "page", required = false, defaultValue = "1") Integer page ,
            @RequestParam(name = "limit", required = false, defaultValue = "20")Integer limit ,
            @RequestParam(name = "sort", required = false, defaultValue = "add_time")String sort ,
            @RequestParam(name = "order", required = false, defaultValue = "desc") String  order
            ){

        IPage<DtsUser> ipage = userService.queryPage(page, limit, sort, order);

        Map<String,Object> data = new HashMap<>();
        data.put("total", ipage.getTotal());
        data.put("items", ipage.getRecords());

        return ResponseUtil.ok(data);

    }
}
